import java.util.Date;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

public class ShiroMain {
	public static void main(String[] args) {
		Factory<SecurityManager> factory = new IniSecurityManagerFactory(
				"classpath:shiro.ini");
		SecurityManager securityManager = factory.getInstance();

		SecurityUtils.setSecurityManager(securityManager);
		String username = "wutianyi";
		String password = "wutianyi";
		AuthenticationToken token = new UsernamePasswordToken(username,
				password);
		
		Subject currentUser = SecurityUtils.getSubject();
		try {
			
			currentUser.login(token);
		} catch(AuthenticationException e) {
			
		}
		//role不能够动态添加
		if(currentUser.hasRole("administrator")) {
			
		} else {
			
		}
		//permittion可以在运行的时候添加
		Session session = currentUser.getSession();
		Session ssession = currentUser.getSession(true);
		session.getAttribute("key");
		Date start = session.getStartTimestamp();
		Date timestamp = session.getLastAccessTime();
		session.setTimeout(1000);
	}
}
